<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    // 1、定义一个数组，求数组中的最大值
        let arr1 = [11, 25, 23, 98, 10, 76, 52]
        function MaxNumber(arr) {
            let maxNumber = arr[0];
            for (i = 0; i < arr.length; i++) {
                if (maxNumber < arr[i]) {
                    maxNumber = arr[i];
                }
            }
            return maxNumber;
        }

        console.log(MaxNumber(arr1))
        
    // 2、已知数组arr中的元素[10,20,0,30,40,0,50]，去除数组中为0的元素，得到一个新数组
        let arr2 = [10,20,0,30,40,0,50]
        function NewArr(arr) {
            let a = [];
            for (i = 0 , j = 0; i < arr.length; i++) {
                if (arr[i] !== 0) {
                    a[j] = arr[i];
                    j++;
                }
            }
            return a;
        }

        console.log(NewArr(arr2))


    // 3、定义一个含有30个整型元素的数组，按顺序分别赋予从2开始的偶数[2, 4, 6, 8, ..., 60],
    // 然后按顺序每五个数求出一个平均值，放在另一个数组中并输出
        let Arra = new Array(30);
        for (i = 1; i <= 30 ;i++){
                Arra[i-1] = i * 2
            }
        // console.log(Arra)
        function countArr (arr) {
            let num = 0;
            let Arrb = [];
            for (i = 0; i < arr.length;) {
                num += arr[i];
                i++;
                if (i % 5 == 0) {
                    Arrb[Arrb.length] = num / 5;
                    num = 0;
                }
            }
            return Arrb;
        }
        
        console.log(countArr(Arra))

    
    // 4、通过循环按行顺序为一个5×5的二维数组a赋1到25的自然数，然后输出该数组
    function twoArr() {
        let arr = []
        for (i = 0; i < 5; i++) {
            arr[i] = [];
            for (j = 0; j < 5; j++) {
                arr[i][j] = (j + i * 5) + 1;
            }
        }
        return arr;
    }
    console.log(twoArr())
    </script>
</body>
</html>